package particlesystem.core {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Matrix;
	import flash.geom.Point;

	/**
	 * @author robertthurston
	 */
	public class ParticleCanvas extends Bitmap {

		private var point : Point;
		private var matrix : Matrix;

		public function ParticleCanvas(width : Number, height : Number) {
			super(new BitmapData(width, height), "auto", true);
			
			point = new Point();
			matrix = new Matrix();
		}

		public function draw(source : BitmapData, x : Number, y : Number) : void {
			matrix.tx = x;
			matrix.ty = y;
			
			bitmapData.draw(source, matrix);
			smoothing = true;
		}

		public function copyPixels(source : BitmapData, x : Number, y : Number, alphaBitmapData : BitmapData) : void {
			point.x = x;
			point.y = y;
			
			bitmapData.copyPixels(source, source.rect, point, alphaBitmapData, null, true);
			smoothing = true;
		}

		public function clear() : void {
			bitmapData.fillRect(bitmapData.rect, 0x00000000);
		}

		public function lock() : void {
			bitmapData.lock();
		}

		public function unlock() : void {
			bitmapData.unlock();
		}
	}
}
